package com.ws.user.role.web;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.ws.common.easyui.util.Page;
import com.ws.common.easyui.util.PageUtils;
import com.ws.user.role.entity.RolePermission;
import com.ws.user.role.service.IRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/admin/user/role/permission")
@Controller
public class RolePermissionWeb {


    @Autowired
    IRolePermissionService rolePermissionService;

    @RequestMapping("{type}")
    public String list(@PathVariable String type){
        return  null;
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Object listData(RolePermission rolePermission,Page page){
        List<RolePermission> rolePermissions=rolePermissionService.list(rolePermission,page);
        return PageUtils.getEasyUiList(rolePermissions);
     }

    @RequestMapping("read")
    @ResponseBody
    public Object read(RolePermission rolePermission){
        if(StrUtil.isNotEmpty(rolePermission.getId())){
            rolePermission= rolePermissionService.read(rolePermission.getId());
        }
        return  rolePermission;
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(RolePermission rolePermission){
        Integer count=rolePermissionService.save(rolePermission);
        return  count;
     }

    @RequestMapping("/delete")
    @ResponseBody
    public Integer delete(String id){
        return  rolePermissionService.delete(id);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(RolePermission rolePermission){
        Integer count=rolePermissionService.insert(rolePermission);
        return  count;
    }

    @RequestMapping("/insertSelective")
    @ResponseBody
    public Object insertSelective(RolePermission rolePermission){
        return rolePermissionService.insertSelective(rolePermission);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Object update(RolePermission rolePermission){
        return rolePermissionService.update(rolePermission);
    }

    @RequestMapping("/listAll")
    @ResponseBody
    public Object listByMap(){
        return  rolePermissionService.listAll();
    }
}
